<template>
	<!-- 我的 -->
	<view class="user-box" :style="'padding-top:'+(barHeight)+'px'">
		<NavBar title="我的"></NavBar>
		<view class="user-container">
			<view class="title">个人信息</view>
			<!-- 头像 -->
			<view class="avator cell-item">
				<text>头像</text>
				<image :src="userEntity.headImgUrl" v-if="userEntity.headImgUrl" alt="头像" />
				<image src="/static/img/tabbar/user.png" alt="头像" v-else />
			</view>
			<!-- 姓名 -->
			<view class="username cell-item">
				<text>姓名</text>
				<text class="right-content">{{userEntity.name||'--'}}</text>
			</view>
			<!-- 手机号 -->
			<view class="telPhone cell-item">
				<text>工号</text>
				<text class="right-content">{{userEntity.jobNumber||'--'}}</text>
			</view>
			<!-- 手机号 -->
			<view class="telPhone cell-item">
				<text>手机号</text>
				<text class="right-content">{{userEntity.telPhone||'--'}}</text>
			</view>
			<!-- 邮箱 -->
			<view class="email cell-item">
				<text>邮箱</text>
				<text>{{userEntity.email||'--'}}</text>
			</view>
			<!-- 角色 -->
			<view class="role cell-item">
				<text>部门</text>
				<text class="right-content">{{userEntity.roleName||'--'}}</text>
			</view>
			<view class="role cell-item">
				<text>角色</text>
				<text class="right-content">{{userEntity.roleName||'--'}}</text>
			</view>
			<view class="role cell-item" style="border-bottom: none;">
				<text>性别</text>
				<text class="right-content">{{userEntity.sex||'--'}}</text>
			</view>
			<view class="cell-item" style="margin-top: 5px;border: none;" @click="toMyProject">
				<text>我的项目</text>
				<uni-icons type="right" size="12"></uni-icons>
			</view>
			<view class="logout" @click="logout">
				<text class="iconfont icon-tuichudenglu"></text>
				退出登录
			</view>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue';
	import {
		api,
		post
	} from '@/util/api.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				userEntity: {},
				barHeight: 0, // 手机导航栏高度
			}
		},
		created() {
			this.querySingle()
			this.barHeight = uni.getSystemInfoSync().statusBarHeight + 45;
		},
		methods: {
			querySingle() {
				post(api.UserSingle, {
					id: uni.getStorageSync('userId')
				}).then(res => {
					this.userEntity = res.data
				})
			},
			toMyProject() {
				uni.navigateTo({
					url: '/pages/project/component/MyProject'
				})
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: '您确定要退出系统吗？',
					success: function(res) {
						if (res.confirm) {
							post(api.LogOut, {}).then(res => {
								console.log(res)
							})
							uni.removeStorageSync('userId')
							uni.reLaunch({
								url: "/pages/user/Login",
							})
						}
					},
				})
			}
		}
	}
</script>

<style>
	@import '../../static/css/User.css';
</style>